/**
 * 
 */
package SimulLois;

import org.apache.log4j.Logger;

import SimulLois.interfaces.Lois;

/**
 * @author Propriétaire
 * 
 */
public class Bernoulli implements Lois {
	
	public static Logger	LOG	= Logger.getLogger(Bernoulli.class);
	
	private Double	     p;
	
	public Bernoulli(Double p) {
		this.p = p;
	}
	
	public static Double randBernoulli(Double p) {
		
		LOG.info("invocking Bernoulli generator");
		
		Double u = Math.random();
		Double X;
		if (u < p) {
			X = new Double(0);
		} else {
			X = new Double(1);
		}
		return X;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see main.java.SimulLois.interfaces.Lois#gen()
	 */
	@Override
	public Double gen() {
		return randBernoulli(p);
	}
	
	/**
	 * @return the p
	 */
	public Double getP() {
		return p;
	}
	
	/**
	 * @param p
	 *            the p to set
	 */
	public void setP(Double p) {
		this.p = p;
	}
	
}
